from PyQt5.QtCore import QEvent
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QMessageBox

import ui_mywidget
from SimpleTrayIcon import SimpleTrayIcon


class ShuoGGWidget(QWidget):

    def __init__(self):
        super(ShuoGGWidget, self).__init__()
        self.mywidgetui = ui_mywidget.Ui_Form()
        self.mywidgetui.setupUi(self)
        self.__init_tray()

    def __init_tray(self):
        self.sTray = SimpleTrayIcon(self)
        self.sTray.addMenuLine("Quit", lambda: self.close())
        self.sTray.addMenuLine("Help", self.__slot_help)
        self.sTray.setTip("我就是托盘")
        self.sTray.setIcon(QIcon("myicon.ico"))

    def __slot_help(self):
        QMessageBox.information(self, 'Help', 'No help for you!')
        self.showNormal()

    def changeEvent(self, e):
        if (e.type() == QEvent.WindowStateChange and self.isMinimized()):
            self.hide()
            e.ignore()
        else:
            super().changeEvent(e)
